package com.zichuan.server;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * @author zichuan
 * @version 1.0
 * @Package : com.zichuan.server
 * @Description : TODO
 * @Create on : 2025/2/17 19:35
 */
@Slf4j
@Service
public class MessageServer {

    @Value("${app.exchangeName}")
    private String exchangeName;

    @Resource
    private RabbitTemplate rabbitTemplate;


    public void sendMessage(){
        MessageProperties messageProperties = new MessageProperties();
        messageProperties.setExpiration("25000");
        String msg = "苏江武是sb";
        Message message = MessageBuilder.withBody(msg.getBytes()).build();
        rabbitTemplate.convertAndSend(exchangeName,"order",message);
        log.info("消息发送完毕,发送时间：{}", LocalDateTime.now());
    }

}
